let app = getApp()
const { baseUrl } =  app.globalData

export default (data)=>{
  let url = baseUrl + '/api' + data.url
  let _data = data.data ? data.data: {} 
  let method = data.method ? data.method: 'get'
  method = method.toUpperCase()

  return new Promise(resolve=>{
    wx.request({
      url,
      method,
      data: _data,
      scriptCharset: 'utf-8',
      success: (res) => {
        if(res.data.code===200){
          resolve(res.data)
        }else {
          wx.showToast({
            title: res.data.msg || '',
            icon: 'none',
            during:5000
          });  
        }
      },
      fail:()=>{
        wx.showToast({
          title: '服务器错误，请稍后重试',
          icon: 'none',
          during:5000
        });
      }
    })   
  })
}